package com.practice.ajCollections010.set.hashset;

import java.util.HashSet;
import java.util.Iterator;

/**
 * HashSet 迭代：
 */
public class Traversal {
    public static void main(String[] args) {
        HashSet<String> set = new HashSet<>();
        set.add("A");
        set.add("B");
        set.add("C");

        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()) {
            // do something
            System.out.println(iterator.next());
        }

        System.out.println("=======================");
        for (String item : set) {
            System.out.println(item);
        }

        System.out.println("=======================");
        set.forEach(item -> {
            System.out.println(item);
        });

        System.out.println("=======================");
        set.stream().forEach(item -> {
            System.out.println(item);
        });
    }
}
